# -*- coding: utf-8 -*-
"""
Created on Mon Aug 15 15:46:50 2022

@author: wulong
"""
import numpy as np
from casadi import *

# In[1] Real system parameters
Nx_r = 23
Nuc_r = 7
Nuz_r = 4
Nud_r = 4
Nu_r = Nuc_r + Nuz_r
Ny_r = 2
Delta_r = 1

# System parameters
Cw = 4.2
eps = 1e-8

# PV
npp = 35
nsp = 6
c_pv1 = 0.0025
c_pv2 = 0.000092
c_pv3 = 0.00413
V_max_0 = 29
I_max_0 = 7.412
Sra_pv_0 = 1000
T_pv_0 = 25

# FC
tau_e = 0.8
tau_f = 5
KO2 = 2.52
KH2O = 0.281
KH2 = 0.843
tau_O2 = 2.91
tau_H2O = 78.3
tau_H2 = 26.1

rfc = 0.126
afc = 0.05
bfc = 0.11
R0fc = 8.314
T0fc = 1273
F0 = 96485
IL = 800

Mch4 = 1000/16
Kr = 0.996e-3
N0fc = 384
E0fc = 1.18
fu_d = 0.8
r_HO = 1.145

# MA
Pmt0 = 80
tab0 = 7

tau_mtf = 20
tau_abf = 130
tau_abw = 80
tau_abt = 70

kma1 = -686180
kma2 = 2.14446e4
kma3 = -1.12767e2
kma4 = -3.86296e-2
kma5 = 1.24
kma6 = -4.4285
kma7 = 0.957
kma8 = -11.484

# EC
Aci = 2.4772; Aco = 2.8311; Aei = 2.6377; Aeo = 3.0145
alfar = 4.4760; alfaw = 5.0800
Ccr = 1.3390; Cer = 1.1750; Cs = 0.3940
hspc = 2.6780; hsph = 1.4960; kr = 1.3880
Mcr = 9.7843; Mcs = 94.4869; Mcw = 79.7615
Mer = 11.7681; Mes = 100.6101; Mew = 71.3956
roeg = 22.6020; Vcp = 1.4215e-4
Gcw = 2.8323; tcwi = 28

# BA
Em = 50
R1b = 4.8e-3
R0b = 4.2e-2
C1b = 1296
npb = 4
nsb = 4
Ceb = 200
tau_dc = 0.8

# ST
Mst = 2e4
tsth0 = 12
tstc0 = 7

# BR
Spmp = 5.1e4
rhow = 1e3
ge = 9.8
b0p = -1.0066e-2
b1p = 1.3079e-1
b2p = 3.5522e-1

Qsl0 = 125
delta_twa0 = 15
Gsl0 = 5.9524
tau_ahu = 20

Cbr = 5.14e4
Ubr = 4.0625

# Time scale separation parameters
# =============================================================================
# tau_x5 = tau_H2
# tau_x23 = Cbr/Ubr
# epsilon = tau_x5/tau_x23
# =============================================================================

# Long-term model coefficient
k_pv = 4.51391e-2
k_fc = 40/0.0045
k_mt = 80/0.0066911
k_ab = 75/80
k_ec = 50/110
k_cp = 12.6/50
k_st = 4.2*5
k_pmp = 13.9/5.9524
k_ba = -1.736111e-06
Gab0 = 3.5714
Gec0 = 2.381

# In[2] Day-ahead Optimization
Nx_h = 3
Nuc_h = 5
Nuz_h = 4
Nud_h = 4
Ny_h = 2
Delta_h = 3600

# In[3] Slow EMPC
Nx_s = 5
Nuc_s = 3
Nud_s = 4
Ny_s = 2
Delta_s = 60

# In[4] Fast EMPC 1
Nx_f1 = 7
Nuc_f1 = 2
Nud_f1 = 4
Ny_f1 = 1

# In[5] Fast EMPC 2
Nx_f2 = 6
Nuc_f2 = 1
Nud_f2 = 4
Ny_f2 = 1

# In[6] Fast EMPC 3
Nx_f3 = 5
Nuc_f3 = 1
Nud_f3 = 4
Ny_f3 = 1

# In[7] For three fast subsystems
Delta_f = 5
Nuc_f = Nuc_f1 + Nuc_f2 + Nuc_f3
Nx_f = Nx_f1 + Nx_f2 + Nx_f3